#ifndef UTILITY_H_
#define UTILITY_H_

#include <hge.h>

// ----- Macro -----
#define UPDATE_KEY(h, v, k) ((v) = (h)->Input_GetKeyState(k) ? (v) + 1 : 0)


// ----- Dialog -----
enum SelectFileDialogMode { LOAD, SAVE };
bool SelectFileDialog(char *sFileName, int iSize, HWND hParent, SelectFileDialogMode eMode, char const *sFilter, char const *sDefExt);


// ----- Font -----
class Font
{
public:
	Font();
	~Font();

	bool Create(char const *typeface, int size, bool bold = false);
	void Free();

	void Render(int x, int y, char const *text, DWORD color, bool shadow = false, DWORD shadowColor = 0xFF000000);
	void RenderInRect(int x, int y, int w, int h, char const *text, DWORD color, bool shadow = false, DWORD shadowColor = 0xFF000000);

private:
	HGE			*m_hge;
	HFONTOBJ	m_hFont;
};


// ----- Image -----
class Image
{
public:
	static unsigned char const FullAlpha = 255;

	Image();
	~Image();

	bool Load(char const *filename);
	void Free();

	unsigned char Alpha() const;

	void SetPivit(int x, int y);
	void SetFrameInfo(int width, int height, int columns);
	void SetFrame(int index);

	void SetAddMode(bool add);
	void SetAlpha(unsigned char alpha);

	void SetTextureRect(int x, int y, int w, int h);

	void Render(float x, float y, float rotation = 0.0f, float hscale = 1.0f, float vscale = 0.0f);
	void RenderNumber(float x, float y, unsigned char number);

private:
	HGE		*m_hge;
	int		m_pivitX, m_pivitY;
	int		m_width, m_height;
	int		m_texWidth, m_texHeight;
	int		m_texColumns;
	int		m_frame;
	hgeQuad	m_quad;

	Image(Image const&);
	Image& operator=(Image const&);
};

#endif